package interview.javabase.thread.future;

import java.util.concurrent.*;

/**
 * @author 大硕
 * 2019-03-28 10:04 PM
 **/
public class ThreadPoolDemo {

    public static void main(String[] args) {

        ExecutorService newCache = Executors.newCachedThreadPool();
        Future<String> res1 = newCache.submit(new MyCallable());
        Future<String> res2 = newCache.submit(new MyCallable());
        Future<String> res3 = newCache.submit(new MyCallable());
        Future<String> res = newCache.submit(new MyCallable());

        if (!res.isDone()) {
            System.out.println("future not finished");
        }
        try {
            System.out.println("......");
            System.out.println(res.get());
            System.out.println(res1.get());
            System.out.println(res2.get());
            System.out.println(res3.get());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            newCache.shutdown();
        }
    }
}